18. Know When to Quit Quiz
Quiz
Modify the martingale()
method by adding an extra if
statment that checks if the money
value has reached or exceeded the target specified, i.e:
if(money >= target)
If it has, then the code should break out of the while loop using the break;
statement
Start Quiz:
public int martingale() {
int money = 1000;
int target = 1200;
int bet = 10;
while (money > bet) {
boolean win = play();
if (win) {
money += bet;
bet = 10;
} else {
money -= bet;
bet *= 2;
}
}
return money;
}